package com.sophialex.health.record.common.showKtable;

import java.math.BigDecimal;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

import com.sophialex.health.common.platform.SuperContext;
import com.sophialex.health.common.platform.util.TimeHelper;
import com.sophialex.health.record.common.util.DataToString;
import com.sophialex.health.record.common.util.ParamUtil;
import com.sophialex.health.record.common.util.PublicConstants;
import com.sophialex.health.record.common.util.StoreUtil;
import com.sophialex.health.record.common.util.SystemUtil;
import com.sophialex.health.system.frame.print.ReportPtnBean;
import com.sophialex.health.system.frame.print.TabHeadBean;
import com.sophialex.health.system.frame.resource.RcpResourceManager;
import com.sophialex.health.system.frame.util.Assert;
import com.sophialex.health.system.frame.util.NumberUtil;
import com.sophialex.health.system.frame.widgets.dbTable.DataForMat;

import de.kupzog.ktable.KTableCellEditor;
import de.kupzog.ktable.KTableCellRenderer;
import de.kupzog.ktable.KTableSortedModel;
import de.kupzog.ktable.SWTX;
import de.kupzog.ktable.editors.KTableCellEditBase;
import de.kupzog.ktable.editors.KTableCellEditorText;
import de.kupzog.ktable.renderers.CheckableCellRenderer;
import de.kupzog.ktable.renderers.FixedCellRenderer;
import de.kupzog.ktable.renderers.TextCellRenderer;

public class ShowKTableModel extends KTableSortedModel {

	/*
	 * 需要加监听 作用为：保存当前表格的宽度 table.addDisposeListener(new DisposeListener() {
	 * public void widgetDisposed(DisposeEvent e) { ((ShowKTableModel)
	 * table.getModel()).saveStore(); } });
	 */
	private Font HeaderFont = SuperContext.f10;
	private Font font = SystemUtil.tabFont;

	static Color red = new Color(Display.getDefault(), new RGB(255, 0, 0));
    
	/**
	 * 选中行颜色
	 */
	private Color BGROWFOCUS = new Color(Display.getDefault(), new RGB(119, 158,245)); 
	private Map<Color, List<Integer>> colorMap = new HashMap<Color, List<Integer>>();

	private Color Foreground = SystemUtil.Table_color;
	private Color backgroundColor = SystemUtil.Table_Background;
	private Color rowBackgroundColor = SystemUtil.Table_GroupBackground;
	private Color rowColor = SystemUtil.Table_Groupcolor;
	private int rowHeight = SystemUtil.Table_Height;
	private int HeaderHeight = SystemUtil.Table_Height;
	private Color RemarkForeground = SystemUtil.RemarkTable_color;
	// private Color

	private String[] columnTitles;
	String[] columnProperties;

	public String[] getColumnProperties() {
		return columnProperties;
	}

	String[][] printData;

	private Map<String, String[]> doubleMap = new HashMap<String, String[]>();

	// for 药房药库
	private boolean haveCheckbox = false;// 第一列为Checkbox

	private int rowCount;
	private int columnCount;

	private int fixRowCount;
	private int fixColumnCount;

	private int[] columnWidths;

	private int[] columnAligns;

	private Map<Integer, Object> rowMap = new Hashtable<Integer, Object>();

	private HeaderCellRenderer m_FixedRenderer = new HeaderCellRenderer(
			FixedCellRenderer.STYLE_FLAT | FixedCellRenderer.INDICATION_SORT
					| FixedCellRenderer.INDICATION_FOCUS
					| FixedCellRenderer.INDICATION_CLICKED);

	private final TextCellRenderer m_textRenderer = new TextCellRenderer(
			TextCellRenderer.INDICATION_FOCUS_ROW);

	private RemarkTextCellRenderer m_textRemarkRenderer = new RemarkTextCellRenderer(
			RemarkTextCellRenderer.INDICATION_FOCUS_ROW);

	private KTableCellRenderer m_CheckableRenderer = new CheckableCellRenderer(
			CheckableCellRenderer.INDICATION_CLICKED
					| CheckableCellRenderer.INDICATION_FOCUS);
	public List<Object> oldDataList;
	private String checkboxPropertie;// 复选按钮的列对应数据库字段
	private String datePatten = "MM-dd HH:mm";// 日期格式
	private static final NumberFormat numberFormater = NumberFormat
			.getNumberInstance();

	// Added by CYX 2010.01.04 ,改变显示的值,与LabelProvider类似
	private ISKJoinOutValue joinOut = null;
	private String key;
	private String[] widths;
	private boolean addCountCol = true;// 加入第一列为行数列
	private Integer beginRemarkRow;// 表格下面的拼节表格的起始位置
	private int[] ncolumn = null;
	private boolean editable = false;
	private int[] colorColumn = null;
	private List<Integer> colorRow = new ArrayList<Integer>();
	private Color columnColor;
	private Color rowListColor;
	private KTableCellEditBase kTableCellEditBase = new KTableCellEditBase();
	private ReportPtnBean ptnBean;

	public ReportPtnBean getPtnBean() {
		initPrintData();
		ptnBean.setRow(printData);
		return ptnBean;
	}

	private void initPrintData() {
		printData = new String[rowCount + 1][];
		printData[0] = getColumnProperty();
		String[] data;
		for (int i = 0; i < rowCount; i++) {
			Object obj = rowMap.get(i);
			data = new String[columnProperties.length - 1];
			for (int j = 1; j < columnProperties.length; j++) {
				String fieldName = columnProperties[j];
//				Object value = PublicConstants.getProperty(obj, fieldName);
				
				Object value = null;
				try {
					value = BeanUtils.getProperty(obj, fieldName);
				}
				catch(Exception e) {
					e.printStackTrace();
				}
				
				data[j - 1] = getValue(i + 1, j, value);
			}
			printData[i + 1] = data;
		}
	}

	public String[][] getPrintData() {
		return printData;
	}

	public Map<String, String[]> getDoubleMap() {
		return doubleMap;
	}

	public void setDoubleMap(Map<String, String[]> doubleMap) {
		this.doubleMap = doubleMap;
	}

	/*
	 * dataList数据 columnTitles列名 columnProperties列对应数据库字段 columnWidths列宽
	 * fixRowCount行固定列数 fixColumnCount列固定列数 haveCheckbox是否有勾选的复选按钮
	 * checkboxPropertie复选按钮的列对应数据库字段 datePatten日期格式
	 */
	public ShowKTableModel(List<Object> dataList, String key,
			boolean addCountCol, String[] columnTitles,
			String[] columnProperties, int[] columnWidths, int fixRowCount,
			int fixColumnCount, String datePatten, boolean haveCheckbox,
			String checkboxPropertie) {
		this.key = key;
		this.addCountCol = addCountCol;
		widths = StoreUtil.getColumnWidth(key);
		this.haveCheckbox = haveCheckbox;
		this.checkboxPropertie = checkboxPropertie;
		this.columnProperties = columnProperties;
		this.datePatten = datePatten;
		init(dataList, columnTitles, columnProperties, columnWidths,
				fixRowCount, fixColumnCount);
	}

	/*
	 * dataList数据 columnTitles列名 columnProperties列对应数据库字段 columnWidths列宽
	 * fixRowCount行固定列数 fixColumnCount列固定列数 datePatten日期格式
	 */
	public ShowKTableModel(List<Object> dataList, String key,
			boolean addCountCol, String[] columnTitles,
			String[] columnProperties, int[] columnWidths, int fixRowCount,
			int fixColumnCount, String datePatten, int[] ncolumn,
			boolean editable, int[] colorColumn, Color columnColor,
			KTableCellEditBase kTableCellEditBase) {
		this.ncolumn = ncolumn;
		this.editable = editable;
		this.columnColor = columnColor;
		this.kTableCellEditBase = kTableCellEditBase;
		this.colorColumn = colorColumn;
		this.key = key;
		this.addCountCol = addCountCol;
		widths = StoreUtil.getColumnWidth(key);
		this.datePatten = datePatten;
		init(dataList, columnTitles, columnProperties, columnWidths,
				fixRowCount, fixColumnCount);
	}

	public List<Object> getData() {
		List<Object> dataList = new ArrayList<Object>();
		dataList.addAll(oldDataList);
		for (int i = getFixedHeaderRowCount(); i < this.rowCount; i++) {
			Object obj = dataList.get(i);
			for (int j = 0; j < columnCount; j++) {
				String fieldName = columnProperties[j];
				if (fieldName != null && !fieldName.trim().equals("")) {
//					Object value = PublicConstants.getProperty(obj, fieldName);
//					PublicConstants.setProperty(obj, fieldName, value);
					Object value;
					try {
						value = BeanUtils.getProperty(obj, fieldName);
						BeanUtils.setProperty(obj, fieldName, value);
					}
					catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
			dataList.set(i, obj);
		}
		return dataList;
	}

	public void setEditColumn(int[] ncolumn, boolean editable) {

		this.ncolumn = ncolumn;
		this.editable = editable;
	}

	public void setColorRow(List<Integer> colorRow, Color rowListColor) {
		colorMap.put(rowListColor, colorRow);
		// this.colorRow = colorRow;
		// this.rowListColor = rowListColor;
	}

	public void setColorRow(List<Integer> colorRow) {

		this.colorRow = colorRow;

	}

	public List<Integer> getColorRow() {
		return colorRow;
	}

	public Object getRow(int row) {
		return rowMap.get(mapRowIndexToModel(row) - 1);
	}

	public void setData(List<Object> dataList) {
		if (dataList != null) {
			rowCount = dataList.size();
			oldDataList = dataList;
		} else {
			oldDataList = new ArrayList();
			rowCount = 0;
		}
		if (ptnBean == null)
			initPtnBean();
		rowMap.clear();
		for (int i = 0; i < rowCount; i++) {
			Object obj = dataList.get(i);
			rowMap.put(i, obj);
		}

	}

	private String[] getColumnProperty() {
		if (columnProperties != null) {
			String strs[] = new String[columnProperties.length - 1];
			for (int i = 1; i < columnProperties.length; i++) {
				strs[i - 1] = columnProperties[i];
			}
			return strs;
		}
		return null;
	}

	/**
	 * Added by CYX 读取嵌套属性的值
	 * 
	 * @param obj
	 * @param fieldName
	 * @return
	 */
	private Object getProperty(Object obj, String fieldName) {
		if (obj == null || fieldName == null) {
			return null;
		}
		Object tempObj = obj;
		Object value = null;
		String[] fieldList = fieldName.split("\\.");
		for (int index = 0; index < fieldList.length; index++) {
			if (tempObj == null) {
				break;
			}
//			value = PublicConstants.getProperty(tempObj, fieldList[index]);

			try {
				value = BeanUtils.getProperty(tempObj, fieldList[index]);
			}
			catch(Exception e) {
				e.printStackTrace();
			}
			
			tempObj = value;

		}
		return value;
	}

	private void init(List<Object> dataList, String[] columnTitles,
			String[] columnProperties, int[] columnWidths, int fixRowCount,
			int fixColumnCount) {
		numberFormater.setMaximumFractionDigits(2);
		numberFormater.setGroupingUsed(false);
		this.columnProperties = columnProperties;
		this.columnTitles = columnTitles;
		if (columnProperties != null) {
			columnCount = columnProperties.length;
		} else {
			columnCount = 0;
		}

		this.columnWidths = columnWidths;

		this.fixRowCount = fixRowCount;
		this.fixColumnCount = fixColumnCount;

		m_FixedRenderer.setAlignment(SWTX.ALIGN_HORIZONTAL_CENTER
				| SWTX.ALIGN_VERTICAL_CENTER | SWTX.WRAP);

		m_FixedRenderer.setFont(HeaderFont);

		m_textRenderer.setFont(font);

		m_textRenderer.COLOR_BGROWFOCUS = BGROWFOCUS;

		FixedCellRenderer.COLOR_LINE_LIGHTGRAY = new Color(
				Display.getDefault(), new RGB(0xC2, 0xC2, 0xC2));
		setData(dataList);
		initialize();
	}

	/**
	 * 初始化打印bean
	 */
	public void initPtnBean() {
		if (columnProperties != null && columnTitles != null
				&& columnWidths != null) {
			ptnBean = new ReportPtnBean();
			ArrayList<TabHeadBean> list = new ArrayList<TabHeadBean>();
			TabHeadBean bean;
			if (addCountCol) {
				for (int i = 1; i < columnProperties.length; i++) {
					bean = new TabHeadBean(columnProperties[i],
							columnTitles[i], String.valueOf(columnWidths[i]),
							getAlingn(i));
					list.add(bean);
				}
			} else {
				for (int i = 0; i < columnProperties.length; i++) {
					bean = new TabHeadBean(columnProperties[i],
							columnTitles[i], String.valueOf(columnWidths[i]),
							getAlingn(i));
					list.add(bean);
				}
			}
			ptnBean.setHead(list);
		}
	}

	private String getAlingn(int i) {
		if (columnAligns == null)
			return TabHeadBean.LEFT;

		int j = columnAligns[i];
		switch (j) {
		case ShowKTable.L:
			return TabHeadBean.LEFT;
		case ShowKTable.C:
			return TabHeadBean.CENTER;
		case ShowKTable.R:
			return TabHeadBean.RIGHT;
		default:
			return TabHeadBean.RIGHT;
		}
	}

	@Override
	public Point doBelongsToCell(int col, int row) {
		if (isFixedCell(col, row))
			if (col == 0) {
				return new Point(col, row);
			} else {
				if (getContent(col, row) != null
						&& getContent(col, row)
								.equals(getContent(col - 1, row))) {
					return new Point(col - 1, row);
				} else {
					return new Point(col, row);
				}
			}
		else
			return new Point(col, row);
	}

	@Override
	public KTableCellEditor doGetCellEditor(int col, int row) {
		// if (haveCheckbox && columnProperties[col].equals(checkboxPropertie)
		// && row >= getFixedHeaderRowCount()) {
		// Rectangle imgBounds = CheckableCellRenderer.IMAGE_CHECKED
		// .getBounds();
		// Point sensible = new Point(imgBounds.width, imgBounds.height);
		// return new KTableCellEditorCheckbox2(sensible,
		// SWTX.ALIGN_HORIZONTAL_CENTER, SWTX.ALIGN_VERTICAL_TOP);
		// }
		if (editable && ncolumn != null && ncolumn.length > 0) {
			for (int column : ncolumn) {
				if (col == column) {
					KTableCellEditorText text = new KTableCellEditorText();
					text.setKTableCellEditBase(kTableCellEditBase);
					return text;
				}
			}
		}
		return null;
	}

	@Override
	public KTableCellRenderer doGetCellRenderer(int col, int row) {
		if (haveCheckbox && columnProperties[col].equals(checkboxPropertie)
				&& row >= getFixedHeaderRowCount()) {
			return m_CheckableRenderer;
		}
		if (isHeaderCell(col, row)) {
			// 表头
			m_FixedRenderer.setFont(HeaderFont);
			return m_FixedRenderer;
		}

		// 表格下面的拼节表格
		if (beginRemarkRow != null && row >= beginRemarkRow) {
			if (this.columnAligns != null) {
				m_textRemarkRenderer.setAlignment(columnAligns[col]
						| SWTX.ALIGN_VERTICAL_TOP | SWTX.WRAP);
			}
			m_textRemarkRenderer.setFont(font);
			m_textRemarkRenderer.setForeground(RemarkForeground);
			m_textRemarkRenderer.setBackground(backgroundColor);
			return m_textRemarkRenderer;
		}

		if (this.columnAligns != null) {
			m_textRenderer.setAlignment(columnAligns[col]
					| SWTX.ALIGN_VERTICAL_TOP | SWTX.WRAP);
		}

		m_textRenderer.setFont(font);
		m_textRenderer.setForeground(Foreground);
		m_textRenderer.setBackground(backgroundColor);
		if (colorColumn != null && colorColumn.length > 0) {
			for (int column : colorColumn) {
				if (col == column) {
					m_textRenderer.setForeground(columnColor);
				}
			}
		}
		if (row % 2 == 0) {
			m_textRenderer.setBackground(rowBackgroundColor);
			// m_textRenderer.setForeground(rowColor);
		}
		if (editable && ncolumn != null && ncolumn.length > 0) {
			for (int column : ncolumn) {
				if (col == column) {
					m_textRenderer.setBackground(RcpResourceManager
							.getColor(SWT.COLOR_WHITE));
				}
			}
		}
		if (!colorMap.isEmpty()) {
			List<Integer> list;
			Iterator<Color> iterator = colorMap.keySet().iterator();
			Color rowColor;
			while (iterator.hasNext()) {
				rowColor = iterator.next();
				list = colorMap.get(rowColor);
				if (list != null && list.size() > 0) {
					for (int rowi : list) {
						if (row - 1 == rowi) {
							m_textRenderer.setBackground(rowColor);
						}
					}
				}
			}
		}
		// if (colorRow != null && colorRow.size() > 0) {
		// for (int rowi : colorRow) {
		// if (row - 1 == rowi) {
		// m_textRenderer.setBackground(rowListColor);
		// }
		// }
		// }

		return m_textRenderer;
	}

	public void clearColorMap() {
		colorMap.clear();
	}

	public Object getContent(int col, int row) {
		if (addCountCol && col < 1) {
			if (col == 0 && row == 0) {
				return "";
			}
			return row;
		}
		if (row < getFixedHeaderRowCount()) {
			return this.columnTitles[col];
		}
		Object obj = rowMap.get(row - this.fixRowCount);
		String fieldName = columnProperties[col];
		Object value = PublicConstants.getProperty(obj, fieldName);
		if (haveCheckbox && columnProperties[col].equals(checkboxPropertie)
				&& row >= getFixedHeaderRowCount()) {
			return value;
		}

		if (value == null)
			value = "";

		return value;
	}

	@Override
	public Object doGetContentAt(int col, int row) {
		if (addCountCol && col < 1) {
			if (col == 0 && row == 0) {
				return "";
			}
			return row;
		}
		// TODO 这里会造成所有的固定行都显示表头
		if (row < getFixedHeaderRowCount()) {
			return this.columnTitles[col];
		}
		Object obj = rowMap.get(row - this.fixRowCount);
		String fieldName = columnProperties[col];
//		Object value = PublicConstants.getProperty(obj, fieldName);
		Object value;
		try {
			value = BeanUtils.getProperty(obj, fieldName);
			return getValue(row, col, value);
		}
		catch(Exception e) {
			e.printStackTrace();
		}
		return null;
		
	}

	private String getValue(int row, int col, Object value) {
		if (haveCheckbox && columnProperties[col].equals(checkboxPropertie)
				&& row >= getFixedHeaderRowCount()) {
			return value.toString();
		}
		if (value == null)
			value = "";

		if (value instanceof Double) {
			value = getDoubleValue(col, value);
		} else if (value instanceof BigDecimal) {
			value = numberFormater.format(((BigDecimal) value));
			try {
				value = numberFormater.parse(value.toString()).doubleValue();
			} catch (ParseException e) {
				e.printStackTrace();
			}
		} else if (value instanceof Float) {
			value = numberFormater.format(((Float) value));
			try {
				value = numberFormater.parse(value.toString()).floatValue();
			} catch (ParseException e) {
				e.printStackTrace();
			}
		} else if (value instanceof Integer) {
			value = numberFormater.format(((Integer) value));
			try {
				value = numberFormater.parse(value.toString()).intValue();
			} catch (ParseException e) {
				e.printStackTrace();
			}
		} else if (value instanceof Boolean) {
			value = ((Boolean) value != null && (Boolean) value) ? "√" : "";
		} else if (value instanceof Date) {
			value = TimeHelper.dateToString((Date) value, datePatten);
		}
//		if (value instanceof String) {
//			try {
//				if (Double.valueOf(value.toString()) >= 1D) {
//				} else if (Double.valueOf(value.toString()) == 0D) {
//					return "0";
//				} else {
//					
//				}
//			} catch (Exception e) {
//			}
//		}
		if (!Assert.isNull(this.joinOut)) {
			value = joinOut.getFieldValue(getRow(row), columnProperties[col],
					value);
			return (String) value;
		}
		// Added by CYX
		return value.toString();
	}

	private Object getDoubleValue(int col, Object value) {
		if (doubleMap.size() > 0) {
			String str = columnProperties[col];
			Iterator<String> iterator = doubleMap.keySet().iterator();
			String key;
			String[] properties;
			while (iterator.hasNext()) {
				key = iterator.next();
				properties = doubleMap.get(key);
				if (properties != null) {
					for (String s : properties) {
						if (s.trim().equals(str.trim())) {
							return DataToString.DoubleToString(value, key);
						}
					}
				}
			}
		}
		if(value instanceof Double){
			int pos = 4;
			String str = ParamUtil.getParamValue(ParamUtil.JEXSPOS);//double类型根据金额显示参数控制位数
			if (!Assert.isNull(str)) {
				 pos = Integer.parseInt(str);
			}
				return NumberUtil.getFormatValue((Double) value, pos);
		}else{
			value = DataForMat.toString(value);
		}
		
		return value;
	}

	@Override
	public void doSetContentAt(int col, int row, Object value) {
		if (haveCheckbox && columnProperties[col].equals(checkboxPropertie)
				&& row >= getFixedHeaderRowCount()) {
			Object obj = oldDataList.get(row - this.fixRowCount);
			if (obj != null) {
				String fieldName = columnProperties[col];
//				PublicConstants.setProperty(obj, fieldName, value);
				try {
					BeanUtils.setProperty(obj, fieldName, value);
				}
				catch(Exception e) {
					e.printStackTrace();
				}
				
				rowMap.put(row, obj);
			}

		}
	}

	public int doGetRowCount() {
		return rowCount + fixRowCount;
	}

	public int doGetColumnCount() {
		return columnCount;
	}

	public int getFixedHeaderRowCount() {
		return this.fixRowCount;
	}

	public int getFixedHeaderColumnCount() {
		return this.fixColumnCount;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.kupzog.ktable.KTableModel#getFixedSelectableRowCount()
	 */
	public int getFixedSelectableRowCount() {
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.kupzog.ktable.KTableModel#getFixedSelectableColumnCount()
	 */
	public int getFixedSelectableColumnCount() {
		return 0;
	}

	public boolean isColumnResizable(int col) {
		return true;
	}

	public int getInitialFirstRowHeight() {
		return HeaderHeight;
	}

	public boolean isRowResizable(int row) {
		return true;
	}

	public int getRowHeightMinimum() {
		return 20;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.kupzog.ktable.KTableDefaultModel#getInitialColumnWidth(int)
	 */
	// public int getInitialColumnWidth(int column) {
	// return this.columnWidths[column];
	// }

	@Override
	public int getInitialColumnWidth(int column) {
		if (widths != null && column < widths.length) {
			try {
				return Integer.parseInt(widths[column]);
			} catch (NumberFormatException e) {
				return getDefaultWidth(column);
			}
		} else {
			return getDefaultWidth(column);
		}

	}

	public int getDefaultWidth(int column) {
		if (columnWidths != null && column < columnWidths.length) {
			return columnWidths[column];
		} else {
			return 80;
		}
	}

	public void saveStore() {
		StoreUtil.save(StoreUtil.COLUMN_PROPERTIE + key, getColumnPropertie());
		StoreUtil.save(StoreUtil.COLUMN_STYLE + key, getColumnStyle());
		StoreUtil.save(StoreUtil.COLUMN_TITLE + key, getColumnTitle());
	}

	/**
	 * 初始化DoubleMap
	 * 
	 * @param flsdj
	 *            零售单价对应的属性
	 * @param fpfdj
	 *            批发单价对应的属性
	 * @param fjhdj
	 *            进货单价对应的属性
	 * @param fje
	 *            金额对应的属性
	 */
	public void initDoubleMap(String[] flsdj, String[] fjhdj, String[] fpfdj,
			String[] fje) {
		doubleMap.put(DataToString.flsdj, flsdj);
		doubleMap.put(DataToString.fjhdj, fjhdj);
		doubleMap.put(DataToString.fpfdj, fpfdj);
		doubleMap.put(DataToString.fje, fje);
	}

	public String getColumnWidth() {
		int column = getColumnCount();
		StringBuffer buffer = new StringBuffer("");
		for (int i = 0; i < column; i++) {
			if (i == 0) {
				buffer.append(getColumnWidth(i));
			} else {
				buffer.append(StoreUtil.SEPARTER).append(getColumnWidth(i));
			}
		}
		return buffer.toString();
	}

	public String getColumnTitle() {
		int index = columnTitles.length;
		String str = "";
		for (int i = 0; i < index; i++) {
			if ("".equals(str)) {
				str = columnTitles[i];
			} else {
				str = str + StoreUtil.SEPARTER + columnTitles[i];
			}
		}
		return str;
	}

	public String getColumnPropertie() {
		int index = columnProperties.length;
		String str = "";
		for (int i = 0; i < index; i++) {
			if ("".equals(str)) {
				str = columnProperties[i];
			} else {
				str = str + StoreUtil.SEPARTER + columnProperties[i];
			}
		}
		return str;
	}

	public String getColumnStyle() {
		int index = columnAligns.length;
		String str = "";
		String temp = "";
		for (int i = 0; i < index; i++) {
			temp = columnProperties[i] + StoreUtil.SEPARTER_fen
					+ columnAligns[i];
			if ("".equals(str)) {
				str = temp;
			} else {
				str = str + StoreUtil.SEPARTER + temp;
			}
		}
		return str;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.kupzog.ktable.KTableDefaultModel#getInitialRowHeight()
	 */
	public int getInitialRowHeight(int row) {
		if (row < getFixedHeaderRowCount()) {
			return this.HeaderHeight;
		}
		return this.rowHeight;
	}

	public int getHeaderHeight() {
		return HeaderHeight;
	}

	public void setHeaderHeight(int headerHeight) {
		HeaderHeight = headerHeight;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see de.kupzog.ktable.KTableDefaultModel#doGetTooltipAt(int, int)
	 */
	public String doGetTooltipAt(int col, int row) {
		return "";
	}

	public void setColumnAligns(int[] aligns) {
		this.columnAligns = aligns;
	}

	public void setColumnWidths(int[] columnWidths) {
		this.columnWidths = columnWidths;
	}

	public void setRowHeight(int rowHeight) {
		this.rowHeight = rowHeight;
	}

	public void setFixRowCount(int fixRowCount) {
		this.fixRowCount = fixRowCount;
	}

	public void setFixColumnCount(int fixColumnCount) {
		this.fixColumnCount = fixColumnCount;
	}

	/**
	 * added by CYX 设置joinout
	 */
	public void setJoinOut(ISKJoinOutValue joinOut) {
		this.joinOut = joinOut;
	}

	/*
	 * 表格下面的拼节表格的起始位置
	 */
	public void setBeginRemarkRow(Integer beginRemarkRow) {
		this.beginRemarkRow = beginRemarkRow;
	}

	public Integer getBeginRemarkRow() {
		return beginRemarkRow;
	}

	public void setKTableCellEditBase(KTableCellEditBase kTableCellEditBase) {
		this.kTableCellEditBase = kTableCellEditBase;
	}

}
